package com.cooksys.film_rental.validation;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

import org.springframework.beans.factory.annotation.Autowired;

import com.cooksys.film_rental.bo.UserBo;
import com.cooksys.film_rental.model.User;
import com.cooksys.film_rental.validation.constraints.UniqueUsername;

public class UniqueUsernameValidator implements
		ConstraintValidator<UniqueUsername, String> {

	@Autowired
	UserBo userBo;

	@Override
	public void initialize(UniqueUsername constraintAnnotation) {
		// TODO Auto-generated method stub

	}

	@Override
	public boolean isValid(String value, ConstraintValidatorContext context) {
		User user = userBo.getUserByUserId(value);
		
		return (user == null);
	}

}
